Settings


Many different functions need to be able to monitor the status that the scales are operating in, and also make changes to those variables. We will incorporate all of these global variables into a single structure called the settings module. Using a structure is one of many ways to handle this behavior, but it gives us several advantages:
  • It improves code tidiness and readability.
  • If we need to save the state of the program, we can simply send za single object to the TLR, rather than dozens of separate variables.

The last point is one of the biggest advantages, and also helps to clarify what variables should be part of the settings? Everyone is free to add variables to the struct, as long as they relate to the operating state of the program. Also remember to check here, and in the global variables page before you make a new additon.

Format


Here are a few quick guidelines on how to use the settings module:
  • Most values will be boolean flags or state markers. Even though it is a bit space inefficient, it is easier and more logical than having multiple bits in registers to be read from.
  • Although it isn't always necessary, try to use functions to modify the variables, instead of just reading/writing the variable directly. If we do this correctly, it will help us make changes further on in development.

struct Settings
{
char factory /*flag if we are operating in factory mode*/
char activeTask /*weigh, tare, count, statistics, raw_data, etc.*/

char LCD; /*Should output go to the LCD screen?*/
char serial; /*Should output go to the serial terminal?*/
char speech; /*Should output go to the speaking module?*/

char